package com.liu.model;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.liu.inter.IPersonOperation;

public class Test {
	public static SqlSessionFactory sqlSessionFactory;
	public static Reader reader;
	static{
		try {
			reader = Resources.getResourceAsReader("Configuration.xml");
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void getPerson(int id){
		SqlSession session = sqlSessionFactory.openSession();
		IPersonOperation personOperation = session.getMapper(IPersonOperation.class);
		Person p = personOperation.selectPersonByID(id);
		System.out.println(p.getUser_name());
		session.close();
	}
	public static void main(String[] args) {
		Test test = new Test();
		test.getPerson(22);
	}
}
